package com.yznote.cloudesk.websocket;

import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.websocket.server.YDWebSocketSession;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ws")
public class WebServerController {
    @GetMapping("/sendMsg")
    public Result sendMsg(@RequestParam("userId") Long userId, @RequestParam("msg") String msg) {
        YDWebSocketSession ydSession = YDWebSocketSession.getYDSession(userId);
        if (ydSession == null) {
            return Result.fail("用户暂未连接至服务器");
        } else {
            try {
                ydSession.sendMessage(msg);
            } catch (Exception e) {
                return Result.fail("消息发送失败");
            }
        }
        return Result.success("消息发送成功");
    }
}
